using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Wzh_CheckAB
{
    public class ButtonItem : ScrollItem
    {
        private Button Btn;
        private Text BtnTxt;
        private GameObject AddTagObj;
        private Action<object> action;
        private object data;
        private void Awake()
        {
            Btn = transform.GetComponent<Button>();
            BtnTxt = transform.Find("Text").GetComponent<Text>();
            var addTra = transform.Find("AddTag");
            if (addTra != null) AddTagObj = addTra.gameObject;
            Btn.onClick.AddListener(OnBtn);
            SetAddTag(false);
        }
        private void OnBtn()
        {
            if (action == null) return;
            action.Invoke(data);
        }
        public void SetInfo(string name, object data,bool isRed, Action<object> action)
        {
            BtnTxt.text = name;
            BtnTxt.color = isRed ? Color.red : Color.black;
            this.data = data;
            this.action = action;
        }

        public void SetAddTag(bool active)
        {
            if (AddTagObj == null) return;
            AddTagObj.SetActive(active);
        }
    }
}